package com.sl.au.service.impl;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.ManagementService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.history.HistoricVariableInstance;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.sl.au.entity.AfterSaleTicketAdvice;
import com.sl.au.entity.AuditNode;
import com.sl.au.entity.AuditRoot;
import com.sl.au.entity.Bid;
import com.sl.au.entity.CustomProcess;
import com.sl.au.entity.ExdeBeforeContract;
import com.sl.au.entity.JPushMsg;
import com.sl.au.entity.MyTask;
import com.sl.au.entity.Quote;
import com.sl.au.entity.QuoteForeign;
import com.sl.au.entity.StorageProperties;
import com.sl.au.entity.User;
import com.sl.au.repository.AfterSaleTicketAdviceRepository;
import com.sl.au.repository.UserRepository;
import com.sl.au.service.ActivitiService;
import com.sl.au.service.AfterSaleOutHouseService;
import com.sl.au.service.AfterSaleTicketService;
import com.sl.au.service.AuditNodeService;
import com.sl.au.service.BidService;
import com.sl.au.service.ContractService;
import com.sl.au.service.ExdeBeforeContractService;
import com.sl.au.service.JGPushService;
import com.sl.au.service.QuoteForeignService;
import com.sl.au.service.QuoteService;

@Service("activitiService")
public class ActivitiServiceImpl extends BaseServiceImpl implements ActivitiService {
	@Autowired
	private RepositoryService repositoryService;

	@Autowired
	private AuditNodeService auditNodeService;
	@Autowired
	AfterSaleOutHouseService afterSaleOutHouseService;
	@Autowired
	AfterSaleTicketService afterSaleTicketService;
	@Autowired
	ExdeBeforeContractService exdeBeforeContractService;

	@Autowired
	QuoteService quoteService;

	@Autowired
	JGPushService jPushService;

	/**
	 * 是否记录审批结点信息
	 */
	@Value("${audit.enable-node-recoding}")
	private boolean enableNodeRecoding = false;

	@Autowired
	private TaskService taskService;

	@Autowired
	private FormService formService;

	@Autowired
	private RuntimeService runtimeService;

	@Autowired
	private ManagementService managementService;

	@Autowired
	private HistoryService historyService;

	@Autowired
	private IdentityService identityService;

	@Autowired
	ProcessEngine processEngine;

	@Autowired
	UserRepository userRepository;

	@Autowired
	StorageProperties properties;

	@Autowired
	BidService bidService;

	@Autowired
	QuoteForeignService quoteForeignService;

	@Autowired
	AfterSaleTicketAdviceRepository ticketAdviceRepository;

	@Autowired
	ContractService contractService;

	private final String processFileBase = "processes";

	/*
	 * 通过流程定义文件名称发布
	 */
	@Override
	public Deployment deploy(List<String> fileList) {
		if (null != fileList) {
			DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
			for (String file : fileList) {
				deploymentBuilder.addClasspathResource(file);
			}
			return deploymentBuilder.deploy();

		}
		return null;
	}

	@Override
	public List<CustomProcess> getCompletedProcessByUser(String userId) {
		List<CustomProcess> list = null;
		List<HistoricProcessInstance> plist = historyService.createHistoricProcessInstanceQuery().startedBy(userId)
				.finished().orderByProcessInstanceStartTime().desc().list();
		list = history2CustomProcess(plist);
		return list;
	}

	@Override
	public void deleteDeployment(String deploymentId) {
		repositoryService.deleteDeployment(deploymentId, true);

	}

	@Override
	public List<CustomProcess> history2CustomProcess(List<HistoricProcessInstance> list) {
		List<CustomProcess> plist = new ArrayList<CustomProcess>();
		for (HistoricProcessInstance hpi : list) {
			ProcessDefinition p = repositoryService.createProcessDefinitionQuery()
					.processDefinitionId(hpi.getProcessDefinitionId()).singleResult();
			CustomProcess rp = new CustomProcess();
			rp.setName(p.getName());
			rp.setProcessInstanceId(hpi.getId());
			rp.setStartDate(hpi.getStartTime());
			rp.setEndDate(hpi.getEndTime());
			plist.add(rp);
		}
		return plist;

	}

	@Override
	public void cancelProcessInstance(String processInstanceId) {
		runtimeService.deleteProcessInstance(processInstanceId, "userCancel");

	}

	@Override
	public ProcessInstance startProcessInstance(String processDefinitionKey, String userId,
			Map<String, String> formData) {

		identityService.setAuthenticatedUserId(userId);// 必须要有，不要找不到发起人哟
		String processDefinitionId = checkDeployByProcessDefinitionKey(processDefinitionKey);

		return formService.submitStartFormData(processDefinitionId, formData);
		// return
		// runtimeService.startProcessInstanceByKey(processDefinitionKey,formData);
	}

	@Override
	public List<CustomProcess> getRunningProcessByUser(String userId) {
		List<HistoricProcessInstance> histories = historyService.createHistoricProcessInstanceQuery().startedBy(userId)
				.orderByProcessInstanceStartTime().desc().unfinished().list();
		return history2CustomProcess(histories);

	}

	@Override
	public List<Task> getTasksByUser(String userId) {
		return taskService.createTaskQuery().taskAssignee(userId).orderByTaskCreateTime().desc().list();

	}

	@Override
	public Object getTaskForm(String taskId) {
		return formService.getRenderedTaskForm(taskId);

	}

	@Override
	public void submitTaskFormData(String taskId, Map<String, String> formData, AuditNode auditNode) {
		String userId = formData.get("userId");
		// 必须在CLAIM之前取啊，不然取不得的了
		Map<String, Object> variables = this.getVariablesByTaskId(taskId);// 提交审批时的变量
		taskService.claim(taskId, userId);
		
		formService.submitTaskFormData(taskId, formData);
		if (this.enableNodeRecoding == true && null != auditNode) {
			// 通过taskId得到相关变量值
			auditNode.setEntityName(variables.get("entityName").toString());
			auditNode.setEntityId(variables.get("entityId").toString());

			String auditState = auditNode.getAuditState();
			String pInstId = null;
			// 更新实体的当前状态:与业务相关
			switch (auditNode.getEntityName()) {
			case "bid":// 投标审批
				Bid bid = bidService.getRepository().getOne(auditNode.getEntityId());
				if (null != bid) {
					bid.setAuditState(auditState);
					pInstId = bid.getProcessInstId();
					bidService.getRepository().save(bid);
					// 记录审批结点数据到数据库
					auditNode.setpInstId(pInstId);
					this.auditNodeService.getRepository().saveAndFlush(auditNode);

					long finishedCount = this.auditNodeService.getRepository().countByPInstIdAndEntityId(pInstId,
							auditNode.getEntityId());
					long auditorNumber = Long.parseLong(variables.get("auditorNumber").toString());
					boolean finished = finishedCount == auditorNumber;
					if (finished == true || auditState.equals("驳回")) {// 审批完成
						bid.setFinishDate(new Date());
						bid.setFinished(true);
						bid.setAuditState(auditState);
					} else {
						bid.setAuditState("审批中");
					}
					bidService.getRepository().save(bid);

				}

				break;
			case "quote-foreign":// 外贸价格单审批
				QuoteForeign quoteForeign = quoteForeignService.getRepository().getOne(auditNode.getEntityId());
				if (null != quoteForeign) {
					pInstId = quoteForeign.getProcessInstId();
					// 记录审批结点数据到数据库
					auditNode.setpInstId(pInstId);
					this.auditNodeService.getRepository().saveAndFlush(auditNode);

					long finishedCount = this.auditNodeService.getRepository().countByPInstIdAndEntityId(pInstId,
							auditNode.getEntityId());
					long auditorNumber = Long.parseLong(variables.get("auditorNumber").toString());
					boolean finished = finishedCount == auditorNumber;
					if (finished == true || auditState.equals("驳回")) {// 审批完成
						quoteForeign.setFinishDate(new Date());
						quoteForeign.setFinished(true);
						quoteForeign.setAuditState(auditState);
					} else {
						quoteForeign.setAuditState("审批中");
					}
					quoteForeignService.getRepository().save(quoteForeign);
				}

				break;
			case "quote":// 普通价格单审批
				Quote quote = quoteService.getRepository().getOne(auditNode.getEntityId());
				if (null != quote) {
					pInstId = quote.getProcessInstId();
					// 记录审批结点数据到数据库
					auditNode.setpInstId(pInstId);
					this.auditNodeService.getRepository().saveAndFlush(auditNode);

					long finishedCount = this.auditNodeService.getRepository().countByPInstIdAndEntityId(pInstId,
							auditNode.getEntityId());
					long auditorNumber = Long.parseLong(variables.get("auditorNumber").toString());
					boolean finished = finishedCount == auditorNumber;
					if (finished == true || auditState.equals("驳回")) {// 审批完成
						quote.setFinishDate(new Date());
						quote.setFinished(true);
						quote.setAuditState(auditState);
					} else {
						quote.setAuditState("审批中");
					}
					quoteService.getRepository().save(quote);
				}

				break;

			case "afterSaleInHouse":// 三包服务审批
				String ticketId = auditNode.getEntityId();
				AfterSaleTicketAdvice ticketAdvice = afterSaleOutHouseService.getRepository()
						.getTicketTab3Data(ticketId).get(0);

				if (null != ticketAdvice) {
					pInstId = ticketAdvice.getProcessInstId();
					// 记录审批结点数据到数据库
					auditNode.setpInstId(pInstId);
					this.auditNodeService.getRepository().saveAndFlush(auditNode);

					long finishedCount = this.auditNodeService.getRepository().countByPInstIdAndEntityId(pInstId,
							ticketId);
					long auditorNumber = Long.parseLong(variables.get("auditorNumber").toString());
					boolean finished = finishedCount == auditorNumber;
					if (finished == true || auditState.equals("驳回")) {// 审批完成
						ticketAdvice.setFinishDate(new Date());
						ticketAdvice.setFinished(true);
						ticketAdvice.setAuditState(auditState);
					} else {
						ticketAdvice.setAuditState("审批中");
						auditState = "审批中";
					}
					ticketAdviceRepository.save(ticketAdvice);
					afterSaleTicketService.setAfterSaleTicketState(ticketId, auditState);
				}

				break;

			case "contract":// 合同审批
				String contractId = auditNode.getEntityId();
				String contractType = variables.get("processDefinitionName").toString();
				AuditRoot contract = contractService.getOne(contractId, contractType);
				if (null != contract) {
					pInstId = contract.getProcessInstId();
					// 记录审批结点数据到数据库
					auditNode.setpInstId(pInstId);
					this.auditNodeService.getRepository().saveAndFlush(auditNode);

					long finishedCount = this.auditNodeService.getRepository().countByPInstIdAndEntityId(pInstId,
							auditNode.getEntityId());
					long auditorNumber = Long.parseLong(variables.get("auditorNumber").toString());
					boolean finished = finishedCount == auditorNumber;
					if (finished == true || auditState.equals("驳回")) {// 审批完成
						contract.setFinishDate(new Date());
						contract.setFinished(true);
						contract.setAuditState(auditState);
					} else {
						contract.setAuditState("审批中");
					}
					contractService.save(contractType, contract);
				}

				break;
			case "beforecontract":// 合同审批
				@SuppressWarnings("unused")
				String beforeId = auditNode.getEntityId();
				ExdeBeforeContract exdeBeforeContract = exdeBeforeContractService.getExdeBeforeContractRepository()
						.getOne(auditNode.getEntityId());
				if (null != exdeBeforeContract) {
					pInstId = exdeBeforeContract.getProcessInstId();
					// 记录审批结点数据到数据库
					auditNode.setpInstId(pInstId);
					this.auditNodeService.getRepository().saveAndFlush(auditNode);

					long finishedCount = this.auditNodeService.getRepository().countByPInstIdAndEntityId(pInstId,
							auditNode.getEntityId());
					long auditorNumber = Long.parseLong(variables.get("auditorNumber").toString());
					boolean finished = finishedCount == auditorNumber;
					if (finished == true || auditState.equals("驳回")) {// 审批完成
						exdeBeforeContract.setFinishDate(new Date());
						exdeBeforeContract.setFinished(true);
						exdeBeforeContract.setAuditState(auditState);
					} else {
						exdeBeforeContract.setAuditState("审批中");
					}
					exdeBeforeContractService.getExdeBeforeContractRepository().save(exdeBeforeContract);
				}
				break;
			}// end of switch

		}

	}

	@Override
	public List<String> getProcessSoureceFiles(String processName) {
		String resourcePath = this.getClass().getClassLoader().getResource("").getPath();// get
																							// the
																							// classes
																							// directory
																							// end
																							// with
																							// "/"
		// if(resourcePath.startsWith("/"))
		// resourcePath=StringUtils.removeStart(resourcePath, "/");
		@SuppressWarnings("unused")
		String processDir = resourcePath + "processes/" + processName;
		/*
		 * Collection<File> fileList = FileUtils.listFiles(new File(processDir),
		 * new String[] { "bpmn", "form" }, false);
		 */
		Collection<File> fileList = null;// wait for replace with nio method.
		if (null == fileList)
			return null;
		@SuppressWarnings("unused")
		List<String> list = new ArrayList<String>();
		for (File f : fileList) {
			list.add(this.processFileBase + "/" + processName + "/" + f.getName());
		}
		return list;
	}

	public RepositoryService getRepositoryService() {
		return repositoryService;
	}

	public void setRepositoryService(RepositoryService repositoryService) {
		this.repositoryService = repositoryService;
	}

	public TaskService getTaskService() {
		return taskService;
	}

	public void setTaskService(TaskService taskService) {
		this.taskService = taskService;
	}

	public FormService getFormService() {
		return formService;
	}

	public void setFormService(FormService formService) {
		this.formService = formService;
	}

	public RuntimeService getRuntimeService() {
		return runtimeService;
	}

	public void setRuntimeService(RuntimeService runtimeService) {
		this.runtimeService = runtimeService;
	}

	public ManagementService getManagementService() {
		return managementService;
	}

	public void setManagementService(ManagementService managementService) {
		this.managementService = managementService;
	}

	public HistoryService getHistoryService() {
		return historyService;
	}

	public void setHistoryService(HistoryService historyService) {
		this.historyService = historyService;
	}

	public IdentityService getIdentityService() {
		return identityService;
	}

	public void setIdentityService(IdentityService identityService) {
		this.identityService = identityService;
	}

	public ProcessEngine getProcessEngine() {
		return processEngine;
	}

	public void setProcessEngine(ProcessEngine processEngine) {
		this.processEngine = processEngine;
	}

	/*
	 * 将指定目录下所有的流程定义文件发布
	 */
	@Override
	public Deployment deployByProcessDirName(String processDefinitionKey) {
		List<String> fileList = this.getProcessSoureceFiles(processDefinitionKey);
		return this.deploy(fileList);
	}

	@Override
	public String checkDeployByProcessDefinitionKey(String processDefinitionKey) {
		List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery()
				.processDefinitionKey(processDefinitionKey).orderByProcessDefinitionVersion().desc().list();
		if (list.size() == 0) {
			this.deployByProcessDirName(processDefinitionKey);
			// 如果流程没有发布，发布之
			repositoryService.createDeployment().addClasspathResource(processDefinitionKey + ".bpmn20.xml").deploy();
			ProcessDefinition pd = repositoryService.createProcessDefinitionQuery()
					.processDefinitionKey(processDefinitionKey).singleResult();
			if (null != pd)
				return pd.getId();
			else
				return null;
		} else
			return list.get(0).getId();

	}

	/*
	 * 得到用户所有的审批任务
	 * 
	 * @
	 */
	@Override
	public List<MyTask> getMyTasksByUser(String userId) {
		List<Task> taskList = this.getTasksByUser(userId);
		List<MyTask> myTaskList = new ArrayList<MyTask>();
		MyTask myTask = null;
		if (taskList.size() > 0) {
			for (Task task : taskList) {
				myTask = new MyTask();
				myTask.setProcessDefinitionId(task.getProcessDefinitionId());
				myTask.setProcessInstanceId(task.getProcessInstanceId());
				myTask.setTaskCreateTime(task.getCreateTime());
				myTask.setTaskId(task.getId());
				myTask.setTaskName(task.getName());
				String taskStarter = historyService.createHistoricProcessInstanceQuery()
						.processInstanceId(myTask.getProcessInstanceId()).singleResult().getStartUserId();
				myTask.setTaskStarter(getUserById(taskStarter));

				myTask.setStarterName(this.userRepository.getOne(taskStarter).getEmpLogin().getName());
				Map<String, Object> variables = this.getVariablesByTaskId(task.getId());
				String entityId = variables.get("entityId").toString();
				String entityName = variables.get("entityName").toString();
				String processDefinitionName = variables.get("processDefinitionName").toString();
				/*
				 * String processDefinitionName =
				 * repositoryService.getProcessDefinition(task.
				 * getProcessDefinitionId()) .getName();// 投标流程
				 * 
				 */ // String processDefinitionId =
					// task.getProcessDefinitionId();//
				myTask.setProcessDefinitionName(processDefinitionName);
				myTask.setEntityId(entityId);
				String taskTitle = this.getTaskTitle(entityId, processDefinitionName);
				if (taskTitle != null) {
					myTask.setTaskTitle(taskTitle);
				}
				String url = "";
				// if (StringUtils.hasText(processDefinitionId)) {
				// String entity= processDefinitionId.split(":")[0];

				if (entityName.equals("contract")) {
					url = "/ui/" + entityName + "/audit-view/" + task.getId() + "/" + entityId + "/"
							+ variables.get("contractType");
				} else {
					url = "/ui/" + entityName + "/audit-view/" + task.getId() + "/" + entityId;
				}

				// }
				myTask.setContentUrl(url);
				myTask.setTaskId(task.getId());
				myTaskList.add(myTask);

			}
		}
		return myTaskList;
	}

	@Override
	public User getUserById(String userId) {
		return null;// (User) getById(userId, User.class);
	}

	@Override
	public Map<String, Object> getVariablesByTaskId(String taskId) {
		return taskService.getVariables(taskId);
	}

	@Override
	public Boolean isProcessInstanceFinished(String processInstanceId) {

		return (null == historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId)
				.singleResult().getEndTime());
	}

	@Override
	public boolean newCheckDeployByProcessDefinitionKey(String key) {
		List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().processDefinitionKey(key)
				.orderByProcessDefinitionVersion().desc().list();
		if (list.size() != 0) {
			return true;
		} else
			return false;
	}

	@Override
	public List<HistoricTaskInstance> findPorcessedTasks(String pInstId) {
		if (!StringUtils.hasText(pInstId))
			return null;
		List<HistoricTaskInstance> list = this.processEngine.getHistoryService().createHistoricTaskInstanceQuery().finished()
				.processInstanceId(pInstId).orderByTaskCreateTime().asc().list();
		return list;
	}

	@Override
	public List<MyTask> getStartedTasks(User user, String key) {
		if (null == user || null == user.getId())
			return null;
		List<MyTask> myTaskList = new ArrayList<>();
		List<CustomProcess> ps = this.getCompletedProcessByUser(user.getId());
		for (CustomProcess p : ps) {
			List<HistoricTaskInstance> tasks = this.findPorcessedTasks(p.getProcessInstanceId());
			if(null!=tasks && tasks.size()>0) {
				MyTask myTask = this.HistoricalTask2MyTask(tasks.get(0), user);

				myTaskList.add(myTask);
			} // for task
		} // for processInst
		return myTaskList;
	}

	@Override
	public List<MyTask> getHistoryTasksByUser(String userId, String key) {
		List<MyTask> myTasks = new ArrayList<>();
		MyTask myTask;
		/*
		 * List<HistoricTaskInstance> list =
		 * this.historyService.createHistoricTaskInstanceQuery().taskAssignee(
		 * userId) .finished().orderByTaskCreateTime().desc().list(); for
		 * (HistoricTaskInstance ht : list) { User user =
		 * userRepository.getOne(userId); myTask =
		 * this.HistoricalTask2MyTask(ht, user); myTasks.add(myTask); }
		 */

		List<HistoricProcessInstance> hpis = historyService.createHistoricProcessInstanceQuery().involvedUser(userId)
				.orderByProcessInstanceStartTime().desc().list();
		for (HistoricProcessInstance pi : hpis) {
			List<HistoricTaskInstance> hlist = historyService.createHistoricTaskInstanceQuery().processInstanceId(pi.getId())
					.finished().orderByTaskCreateTime().desc().list();
			if (null != hlist && hlist.size()>0) {				
				
				User user = userRepository.getOne(userId);
				myTask = this.HistoricalTask2MyTask(hlist.get(0), user);
				myTasks.add(myTask);
			}

		}

		return myTasks;
	}

	private MyTask HistoricalTask2MyTask(HistoricTaskInstance task, User user) {
		MyTask myTask = new MyTask();
		myTask.setTaskId(task.getId());
		myTask.setProcessDefinitionId(task.getProcessDefinitionId());
		myTask.setProcessInstanceId(task.getProcessInstanceId());
		myTask.setTaskCreateTime(task.getCreateTime());
		myTask.setTaskId(task.getId());
		myTask.setTaskName(task.getName());
		
	

		String entityId = "", entityName = "", contractType = "",starter="";
		String processDefinitionName = "";

		myTask.setStarterName(user.getName());
		List<HistoricVariableInstance> list = processEngine.getHistoryService()//
				.createHistoricVariableInstanceQuery()// 创建一个历史的流程变量查询对象
				.processInstanceId(task.getProcessInstanceId())//
				.list();
		if (list != null && list.size() > 0) {
			for (HistoricVariableInstance hvi : list) {
				switch (hvi.getVariableName().toString()) {
				case "entityId":
					entityId = hvi.getValue().toString();
					myTask.setEntityId(entityId);
					break;
				case "entityName":
					entityName = hvi.getValue().toString().toString();
					break;
				case "processDefinitionName":
					processDefinitionName = hvi.getValue().toString().toString();
					myTask.setProcessDefinitionName(processDefinitionName);
					break;
				case "contractType":
					contractType = hvi.getValue().toString().toString();
					break;
				case "starter":
					starter = hvi.getValue().toString().toString();
					break;
				}

			}
			
			User u=userRepository.getOne(starter);
			myTask.setStarterName(u.getName());
			myTask.setTaskStarter(u);
			
			String url = "";

			if (entityName.equals("contract")) {
				url = "/ui/" + entityName + "/audit-view/" + task.getId() + "/" + entityId + "/" + contractType;
			} else {
				url = "/ui/" + entityName + "/audit-view/" + task.getId() + "/" + entityId;
			} // for
			myTask.setContentUrl(url);
			//
			String taskTitle = this.getTaskTitle(entityId, processDefinitionName);
			myTask.setTaskTitle(taskTitle);
		} // if
		return myTask;
	}

	@Override
	public String getTaskTitle(String entityId, String processDefinitionName) {
		String taskTitle = "";
		switch (processDefinitionName) {
		case "普通价格单":
			Quote q = quoteService.getRepository().findOne(entityId);
			taskTitle = q.getName();
			break;
		case "外贸价格单":
			QuoteForeign qf = quoteForeignService.getRepository().findOne(entityId);
			taskTitle = qf.getName();
			break;
		case "投标":
			Bid b = bidService.getRepository().findOne(entityId);
			taskTitle = b.getName();
			break;
		case "三包服务":
			AfterSaleTicketAdvice ticketAdvice = afterSaleOutHouseService.getRepository().getTicketTab3Data(entityId)
					.get(0);
			taskTitle = ticketAdvice.getAfterSaleTicket().getUnitName();// 订货单位
			break;
		case "签订前要点审批":
			ExdeBeforeContract e = exdeBeforeContractService.getExdeBeforeContractRepository().getOne(entityId);
			taskTitle = e.getcProjectName();
			break;
		}

		return taskTitle;
	}
	
}
